using B.S.XZYData.Api.Wrter.Application.Command.AssemblyWorkOrder;
using B.S.XZYData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace B.S.XZYData.Api.Wrter.Controllers
{
    /// <summary>
    /// 装配工单打印接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class AssemblyWorkOrderPrintController : ControllerBase
    {
        private readonly IMediator _mediator;
        
        public AssemblyWorkOrderPrintController(IMediator mediator) 
        { 
            _mediator = mediator; 
        }

        /// <summary>
        /// 打印单个装配工单
        /// </summary>
        /// <param name="id">装配工单ID</param>
        /// <returns>打印数据</returns>
        [HttpGet("{id}")]
        public Task<ApiResult<PrintAssemblyWorkOrderResponseDto>> Print(long id)
        {
            var command = new PrintAssemblyWorkOrderCommand { Id = id };
            return _mediator.Send(command);
        }

        /// <summary>
        /// 批量打印装配工单
        /// </summary>
        /// <param name="request">批量打印请求</param>
        /// <returns>批量打印数据</returns>
        [HttpPost("batch")]
        public Task<ApiResult<List<PrintAssemblyWorkOrderResponseDto>>> BatchPrint([FromBody] BatchPrintAssemblyWorkOrderCommand request)
        {
            return _mediator.Send(request);
        }

        /// <summary>
        /// 打印预览装配工单
        /// </summary>
        /// <param name="id">装配工单ID</param>
        /// <param name="includeQrCode">是否包含二维码</param>
        /// <param name="includeProductDetails">是否包含产品明细</param>
        /// <param name="includeStatistics">是否包含统计信息</param>
        /// <returns>打印预览数据</returns>
        [HttpGet("{id}/preview")]
        public Task<ApiResult<PrintAssemblyWorkOrderResponseDto>> Preview(
            long id, 
            [FromQuery] bool includeQrCode = true, 
            [FromQuery] bool includeProductDetails = true, 
            [FromQuery] bool includeStatistics = true)
        {
            var command = new PreviewAssemblyWorkOrderCommand
            {
                Id = id,
                IncludeQrCode = includeQrCode,
                IncludeProductDetails = includeProductDetails,
                IncludeStatistics = includeStatistics
            };
            return _mediator.Send(command);
        }

        /// <summary>
        /// 获取装配工单打印数据（兼容旧版本）
        /// </summary>
        /// <param name="id">装配工单ID</param>
        /// <returns>打印数据</returns>
        [HttpGet("print/{id}")]
        public Task<ApiResult<PrintAssemblyWorkOrderResponseDto>> GetPrintData(long id)
        {
            var command = new PrintAssemblyWorkOrderCommand { Id = id };
            return _mediator.Send(command);
        }

        /// <summary>
        /// 获取装配工单打印预览数据（兼容旧版本）
        /// </summary>
        /// <param name="id">装配工单ID</param>
        /// <param name="includeQrCode">是否包含二维码</param>
        /// <param name="includeProductDetails">是否包含产品明细</param>
        /// <param name="includeStatistics">是否包含统计信息</param>
        /// <returns>打印预览数据</returns>
        [HttpGet("preview/{id}")]
        public Task<ApiResult<PrintAssemblyWorkOrderResponseDto>> GetPrintPreviewData(
            long id, 
            [FromQuery] bool includeQrCode = true, 
            [FromQuery] bool includeProductDetails = true, 
            [FromQuery] bool includeStatistics = true)
        {
            var command = new PreviewAssemblyWorkOrderCommand
            {
                Id = id,
                IncludeQrCode = includeQrCode,
                IncludeProductDetails = includeProductDetails,
                IncludeStatistics = includeStatistics
            };
            return _mediator.Send(command);
        }
    }
} 